package behavioral.Iterator.inner;

import behavioral.Iterator.IAggregate;
import behavioral.Iterator.IIterator;

public class CustomerAggregate implements IAggregate {

    private Object[] arrSrc;

    public CustomerAggregate(Object[] arrSrc) {
        this.arrSrc = arrSrc;
    }

    @Override
    public IIterator it() {
        return new InnerIterator();
    }


    private class InnerIterator implements IIterator {
        private int index;
        private int size;

        public InnerIterator() {
            this.index = 0;
            this.size = arrSrc.length;
        }

        @Override
        public Object first() {
            this.index = 0;
            return arrSrc[0];
        }

        @Override
        public Object next() {
            if (index >= size) {
                return null;
            }

            return arrSrc[index++];
        }

        @Override
        public boolean hasNext() {
            if (index >= size) {
                return false;
            }

            return true;
        }

        @Override
        public Object currentObject() {
            return arrSrc[index];
        }
    }
}
